<!--
 * @Autor: ZN
 * @LastEditors: ZN
 * @Date: 2023-05-10 16:51:08
 * @LastEditTime: 2023-05-10 17:41:48
 * @Description: 弹窗
-->
<template>
  <teleport to="body">
    <div class="dialog-container" v-show="props.isShow">
      <div
        class="dialog-content"
        :style="`width:${props.width}px; height: ${props.height}px;`"
      >
        <div class="title">{{ props.title }}</div>
        <div class="close" @click="closeClick"></div>

        <div class="dialog-cont">
          <slot></slot>
        </div>
      </div>
    </div>
  </teleport>
</template>

<script setup lang="ts">
import { ref } from "vue";

const props = withDefaults(
  defineProps<{
    width?: string | number;
    height: string | number;
    title: string;
    isShow: boolean;
  }>(),
  {
    width: 750,
    height: 600,
    isShow: false,
  }
);

const emits = defineEmits<{
  (event: "close"): void;
}>();

// 点击关闭
const closeClick = () => {
  emits("close");
};
</script>

<style scoped lang="scss">
.dialog-container {
  width: 100vw;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 999;
  display: flex;
  justify-content: center;
  align-items: center;

  .dialog-content {
    background-color: #fff;
    position: relative;
    display: flex;
    flex-direction: column;

    .title {
      width: 100%;
      height: 40px;
      line-height: 40px;
      border-bottom: 1px solid #eee;
      padding: 0 10px;
      box-sizing: border-box;
      font-family: gjfybxs;
      font-weight: 500;
    }

    .close {
      width: 22px;
      height: 22px;
      position: absolute;
      top: 8px;
      right: 12px;
      background-image: url("@/assets/images/dialog-close.png");
      background-size: 100% 100%;
      cursor: pointer;
    }

    .dialog-cont {
      padding: 10px;
      box-sizing: border-box;
    }
  }
}
</style>
